package config

import (
	"cid-media-api/global"
	"context"
	"github.com/go-redis/redis_rate/v10"
	"github.com/redis/go-redis/v9"
	"log"
)

func InitRedis() {

	addr := AppConfig.Redis.Addr

	options := &redis.Options{
		Addr: addr,
	}

	redisClient := redis.NewClient(options)

	ctx := context.Background()

	_, err := redisClient.Ping(ctx).Result()

	if err != nil {
		log.Fatalf("Failed to connect to Redis, got error: %v", err)
	}

	global.RedisDb = redisClient
	global.RateLimiter = redis_rate.NewLimiter(redisClient)
}
